<!--利率曲线设置-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="利率曲线">

        <baseCombox url="/pricing/comboBox/queryIrcurveFilter.action"   clearable
                    size="small"
                    style="width: 240px"
                    @change="handleQuery"  placeholder="利率曲线"   v-model="queryParams.ircCode" ></baseCombox>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" size="small" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            size="small"
            @click="handleAdd"
            v-hasPermi="['curve:ircurve:ircurveset:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="Edit"
            size="small"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['curve:ircurve:ircurveset:upt']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            size="small"
            :disabled="single"
            @click="handleDelete"
            v-hasPermi="['curve:ircurve:ircurveset:del']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            size="small"
            @click="handleExport"
            v-hasPermi="['curve:ircurve:ircurveset:export']"
        >当页导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            size="small"
            @click="handleExportAll"
            v-hasPermi="['curve:ircurve:ircurveset:export']"
        >全量导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="irCrvSetList"   @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index"  width="50">
      </el-table-column>
      <el-table-column label="曲线代码" align="center" prop="ircCode" :show-overflow-tooltip="true" width="150"/>
      <el-table-column label="曲线名称" align="center" prop="ircName" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="币种" align="center" prop="currency" width="100">
        <template #default="scope">
          <dict-tag :options="CURRENCY" :value="scope.row.currency"/>
        </template>
      </el-table-column>

      <el-table-column label="曲线类型" align="center" prop="ircType" width="100">
        <template #default="scope">
          <dict-tag :options="ircType" :value="scope.row.ircType"/>
        </template>
      </el-table-column>

      <el-table-column label="构建方式" align="center" prop="ircConstructor" width="100">
        <template #default="scope">
          <dict-tag :options="ircConstructor" :value="scope.row.ircConstructor"/>
        </template>
      </el-table-column>
      <el-table-column label="计息基准" align="center" prop="ircDaycount" width="100">
        <template #default="scope">
          <dict-tag :options="dayCounter" :value="scope.row.ircDaycount"/>
        </template>
      </el-table-column>
      <el-table-column label="模型方法" align="center" prop="ircMethod" width="100">
        <template #default="scope">
          <dict-tag :options="ircMethod" :value="scope.row.ircMethod"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="模型方法参数" align="center" prop="ircMethodParam" width="100"/>-->
<!--      <el-table-column label="结算日偏移" hidden="true" align="center" prop="settleDays" width="100"/>-->
      <el-table-column label="标的交易代码" align="center" prop="uICode" />
      <el-table-column label="标的资产类型" align="center" prop="uAType" width="100">
        <template #default="scope">
          <dict-tag :options="A_TYPE" :value="scope.row.uAType"/>
        </template>
      </el-table-column>
      <el-table-column label="标的市场类型" align="center" prop="uMType" >
        <template   #default="scope">
          <dict-tag :options="M_TYPE" :value="scope.row.uMType"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="操作" align="center" width="120" class-name="small-padding">-->
<!--        <template #default="scope">-->
<!--          <el-button-->
<!--              size="small"-->
<!--              type="text"-->
<!--              icon="Edit"-->
<!--              @click="handleUpdate(scope.row)"-->
<!--              v-hasPermi="['system:dict:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--              size="small"-->
<!--              type="text"-->
<!--              icon="Delete"-->
<!--              @click="handleDelete(scope.row)"-->
<!--              v-hasPermi="['system:dict:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" v-model="open" width="50%" :close-on-click-modal="false" append-to-body>
      <el-form ref="icvsetRef" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="10">
        <el-col :span="12">
        <el-form-item label="曲线代码" prop="ircCode">
          <el-input v-model="form.ircCode" :disabled="opFlag"   clearable
                    size="small"   placeholder="请输入曲线代码" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="曲线名称" prop="ircName">
          <el-input v-model="form.ircName" clearable
                    size="small" placeholder="请输入曲线名称" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="计息基准" prop="ircDaycount">
          <DictCombox  v-model="form.ircDaycount" dictType="dayCounter" ></DictCombox>
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="交割币种" prop="currency">
          <DictCombox  v-model="form.currency" dictType="CURRENCY"   ></DictCombox>
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="曲线类型" prop="ircType">
          <DictCombox  v-model="form.ircType" dictType="ircType"   ></DictCombox>
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="构建方式" prop="ircConstructor">
          <DictCombox  v-model="form.ircConstructor" dictType="ircConstructor"   ></DictCombox>
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="利率类型" prop="ircRatetype">
          <DictCombox  v-model="form.ircRatetype" dictType="ircRatetype"   ></DictCombox>
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="标的" prop="uICode">
          <underlyer  ref="underlyer"  v-model="form.uICode" > </underlyer>
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="模型方法" prop="ircMethod">
          <DictCombox  v-model="form.ircMethod" dictType="ircMethod"   ></DictCombox>
        </el-form-item>
        </el-col>
        <el-col :span="24">
        <el-form-item label="模型方法参数" prop="ircMethodParam">
          <el-input v-model="form.ircMethodParam" type="textarea" placeholder="请输入模型方法参数"></el-input>
        </el-form-item>
        </el-col>
        <el-col :span="24">
        <el-form-item label="参考过滤条件" prop="ircRefGfilter">
          <el-input v-model="form.ircRefGfilter" type="textarea" placeholder="请输入参考过滤条件"></el-input>
        </el-form-item>
        </el-col>
      </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="ircurveset">
import {getIrCrvSetList,addIrcCurveSet,uptIrcCurveSet,delIrcCurveSet } from "@/api/curve/ircurve/ircurveset";
import baseCombox from "../../../../xquant/base/baseCombox";
import DictCombox from "../../../../xquant/base/dictCombox";
import Underlyer from "../../../../xquant/base/underlyer";
const { proxy } = getCurrentInstance();
const { M_TYPE,A_TYPE,CURRENCY,ircType,ircConstructor,ircMethod,dayCounter} = proxy.useDict("M_TYPE","A_TYPE","CURRENCY","ircType","ircConstructor","ircMethod","dayCounter");

const irCrvSetList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const opFlag=ref(false);//true时为修改  false为新增
const data = reactive({
  form:{},
  queryParams: {
    pageNum: 1,
    pageSize: 20,
    ircCode: undefined
  },
  rules: {
    ircCode:[{ required: true, message: "曲线代码不能为空", trigger: "blur" }],
    ircName:[{ required: true, message: "曲线名称不能为空", trigger: "blur" }],
    ircDaycount:[{ required: true, message: "计息基准不能为空", trigger: "blur" }],
    currency:[{ required: true, message: "币种不能为空", trigger: "blur" }],
    ircType:[{ required: true, message: "曲线类型不能为空", trigger: "blur" }],
    ircConstructor:[{ required: true, message: "构建方式不能为空", trigger: "blur" }],
    ircRatetype:[{ required: true, message: "利率类型不能为空", trigger: "blur" }],
    uICode:[{ required: false, message: "标的不能为空", trigger: "blur" }],
    ircMethod:[{ required: true, message: "模型方法不能为空", trigger: "blur" }]
  }
});

const { queryParams,form,rules } = toRefs(data);
/** 表单重置 */
function reset() {
  form.value = {
    ircCode:undefined,
    ircName:undefined,
    ircDaycount:'Actual/360',
    currency:undefined,
    ircType:undefined,
    ircConstructor:undefined,
    ircRatetype:undefined,
    uICode:undefined,
    ircMethod:undefined,
    ircMethodParam:undefined,
    ircRefGfilter:undefined
  };
  proxy.resetForm("icvsetRef");
}
/** 查询列表 */
function getList() {
  loading.value = true;
  getIrCrvSetList(queryParams.value).then(response => {
    irCrvSetList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}


/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}



/** 导出按钮操作 */
function handleExport() {
  proxy.download("/marketdata/irCurveStrip/export", {
    ...queryParams.value
  }, `利率曲线定义${new Date().getTime()}.xlsx`);
}

/** 导出按钮操作 */
function handleExportAll() {
  proxy.download("/marketdata/irCurveStrip/export", Object.assign({
    ...queryParams.value
  },{pageSize:''}), `利率曲线定义${new Date().getTime()}.xlsx`);
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  opFlag.value=false;
  open.value = true;
  title.value = "添加曲线定义";
}
/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.ircCode);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}
/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  let ircCode = row.ircCode || ids.value;
  if(Array.isArray(ircCode)){
    ircCode=ircCode[0];
  }
  open.value = true;
  opFlag.value=true;
  getIrCrvSetList({'ircCode':ircCode}).then(response => {
    form.value = response.rows[0];
    if(response.rows[0]!=null&response.rows[0].uICode!=""&&response.rows[0].uICode!=null){
      form.value.uICode=response.rows[0].uICode+','+response.rows[0].uAType+','+response.rows[0].uMType;
     }

    title.value = "修改曲线定义";
  });
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["icvsetRef"].validate(valid => {
    if (valid) {
      if(form.value.uICode!=null&&form.value.uICode!=''){
        let underIds=form.value.uICode.split(',');
        form.value.uiCode=underIds[0];
        form.value.uaType=underIds[1];
        form.value.umType=underIds[2];
      }
      if (opFlag.value==true) {
        uptIrcCurveSet(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addIrcCurveSet(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}
/** 删除按钮操作 */
function handleDelete(row) {
  let ircCode = row.ircCode || ids.value;
  if(Array.isArray(ircCode)){
    ircCode=ircCode[0];
  }
  proxy.$modal.confirm('是否确认删除利率曲线编号为"' + ircCode + '"的数据项？').then(function() {
    return delIrcCurveSet({'ircCode':ircCode});
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}



getList();
</script>
